﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EzyGoEzySystem.Models;

namespace EzyGoEzySystem.Services
{
    public class PaymentService
    {
        public void UpdateBalance(PaymentJournalEntry t, EzyGoEzyDBContext dbContext)
        {
            
            double creditAmount = Math.Round(t.Amount, 2);

            //deduct account of customer
            t.Account.Balance = Math.Round(t.Account.Balance + creditAmount, 2);
            
            // persist to db
            dbContext.SaveChanges();
        }

        public IEnumerable<PaymentJournalEntry> UpdateBalance(IEnumerable<PaymentJournalEntry> entryList, EzyGoEzyDBContext dbContext)
        {
           
            foreach(PaymentJournalEntry entry in entryList)
            {
              UpdateBalance(entry, dbContext);
            }
            return entryList;
        }
    
    }
}